package com.rtx.edi.platform.synctask.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.rtx.api.annotation.RtxActivegatway;
import com.rtx.edi.model.api.bo.ApiMappingInfoBo;
import com.rtx.edi.platform.synctask.service.GatWayService;
import com.rtx.model.dto.edi.EdiInnerRequestDTO;

import cn.hutool.http.HttpRequest;

@RtxActivegatway("EDI接口")
@Service("ApiGatWayService")
public class WmsApiGatWayServiceImpl extends GatWayService{
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	
	@Override
	protected String handleTarget(String targetjson, ApiMappingInfoBo apiInfo) {
		logger.info("目标请求地址：{}",apiInfo.getTargetUrl());
		 
		String request =ediRequestDTO(apiInfo,targetjson);
		
		//设置请求报文
		apiInfo.getContent().setRequestContent(targetjson);
		
		String	result = HttpRequest
				.post(apiInfo.getTargetUrl())
				.body(request)
				.timeout(30000)
				.execute()
				.body();
		
		apiInfo.getContent().setResponseContent(result);
		
		return result;
	}

	//将配置信息转发到目标接口
	private String ediRequestDTO(ApiMappingInfoBo apiInfo,String targetjson) {
		EdiInnerRequestDTO request = new EdiInnerRequestDTO();
		request.setTagetjson(targetjson);
		request.setConfig(apiInfo);
		return com.alibaba.fastjson.JSON.toJSONString(request);
	}
	
}
